package com.dv.web.controller.basic;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.dv.common.utils.DateUtils;
import com.dv.driverless.domain.BasicDriver;
import com.dv.driverless.service.IBasicDriverService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dv.common.annotation.Log;
import com.dv.common.core.controller.BaseController;
import com.dv.common.core.domain.AjaxResult;
import com.dv.common.enums.BusinessType;

import com.dv.common.utils.poi.ExcelUtil;
import com.dv.common.core.page.TableDataInfo;

/**
 * 司机信息Controller
 *
 * @author ruoyi
 * @date 2023-04-06
 */
@RestController
@RequestMapping("/basic/driver")
public class BasicDriverController extends BaseController
{
    @Autowired
    private IBasicDriverService basicDriverService;

    /**
     * 查询司机信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:driver:list')")
    @GetMapping("/list")
    public TableDataInfo list(BasicDriver basicDriver)
    {
        startPage();
        List<BasicDriver> list = basicDriverService.selectBasicDriverList(basicDriver);
        return getDataTable(list);
    }

    /**
     * 导出司机信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:driver:export')")
    @Log(title = "司机信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BasicDriver basicDriver)
    {
        List<BasicDriver> list = basicDriverService.selectBasicDriverList(basicDriver);
        ExcelUtil<BasicDriver> util = new ExcelUtil<BasicDriver>(BasicDriver.class);
        util.exportExcel(response, list, "司机信息数据");
    }

    /**
     * 获取司机信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:driver:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(basicDriverService.selectBasicDriverById(id));
    }

    /**
     * 新增司机信息
     */
    @PreAuthorize("@ss.hasPermi('system:driver:add')")
    @Log(title = "司机信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BasicDriver basicDriver)
    {
        basicDriver.setCreateDate(DateUtils.getNowDate());
        return toAjax(basicDriverService.insertBasicDriver(basicDriver));
    }

    /**
     * 修改司机信息
     */
    @PreAuthorize("@ss.hasPermi('system:driver:edit')")
    @Log(title = "司机信息", businessType = BusinessType.UPDATE)
    @PutMapping ("/edit")
    public AjaxResult edit(@RequestBody BasicDriver basicDriver)
    {
        return toAjax(basicDriverService.updateBasicDriver(basicDriver));
    }

    /**
     * 删除司机信息
     */
    @PreAuthorize("@ss.hasPermi('system:driver:remove')")
    @Log(title = "司机信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(basicDriverService.deleteBasicDriverByIds(ids));
    }
}
